package cn.tedu._04weibo.base.exception;


import cn.tedu._04weibo.base.response.JsonResult;
import cn.tedu._04weibo.base.response.StatusCode;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {
    @ExceptionHandler(IllegalArgumentException.class)
    public JsonResult doHandleIllegalArgumentException(IllegalArgumentException ex){
        String data =ex.getMessage();
        log.error("doHandleIllegalArgumentException"+data);
        return new JsonResult(StatusCode.OPERATION_FAILED,data);
    }
    @ExceptionHandler(RuntimeException.class)
    public JsonResult doHandleRuntimeException(RuntimeException ex){
        String data = ex.getMessage();
        log.error("doHandleRuntimeException:"+data);
        return new JsonResult(StatusCode.OPERATION_FAILED,data);
    }
//    @ExceptionHandler(Throwable.class)
//    public JsonResult doHandleThrowable(Throwable ex){
//        String data = ex.getMessage();
//        log.error("doHandleThrowable:"+data);
//        return new JsonResult(StatusCode.OPERATION_FAILED,data);
//    }
}
